package com.chen.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chen.common.ValidationEnum;
import com.chen.entity.Dict;
import com.chen.entity.Exam;
import com.chen.entity.Validation;
import com.chen.mapper.ExamMapper;
import com.chen.service.IExamService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author personcoder007
 * @since 2022-08-17
 */
@Service
public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IExamService {


    @Autowired
    private ExamMapper examMapper;

    public IPage<Dict> selectPage(Integer pageNum, Integer pageSize, String name, String state) {
//        创建Page对象
        IPage<Dict> page = new Page<Dict>(pageSize, pageNum);
//QueryWrapper如果name不为空进行模糊查询
        QueryWrapper queryWrapper = new QueryWrapper();
        if (!"".equals(name)) {
            queryWrapper.like("name", name);
        }
        if (!"".equals(state)) {
            queryWrapper.like("state", state);
        }

        Page<Dict> selectPage = examMapper.selectPage(new Page<>(pageNum, pageSize), queryWrapper);
        return selectPage;

    }

    public List<Exam> findPage(Integer pageNum, Integer pageSize, String name) {

        HashMap<String, Object> map = new HashMap<>();
        List<Exam> page = null;
        if (!"".equals(name)) {
            map.put("name", name);
        }
        pageNum = (pageNum - 1) * pageSize;
        page = examMapper.findPage(pageNum, pageSize, map);
        return page;
    }

}
